package com.itc.bi.xxljob;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.itc.bi.service.impl.DataSetXxlBobService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: itc-airport-cloud
 * @BelongsPackage: com.itc.bi.xxljob
 * @Author: hecaiy
 * @CreateTime: 2024-07-06  12:08
 * @Description: TODO xxl-job  任务调度handler
 * @Version: 1.0
 */
@Slf4j
@Component
public class DataSetXxlJob {
    @Autowired
    private DataSetXxlBobService dataSetXxlBobService;

    /**
     * sql数据同步方法
     * @throws Exception
     */
    @XxlJob("SqlHandler")
    public void sqlJobHandler()throws Exception{
        log.debug("sql 数据同步方法执行");
        String jobParam = XxlJobHelper.getJobParam();
        JSONObject jsonObject = JSONObject.parseObject(jobParam);
        Long dtId = jsonObject.getLong("dtId");
        if(ObjectUtil.isNotEmpty(dtId)){
            dataSetXxlBobService.processSqlData(dtId);

        }
    }

    /**
     * python数据同步方法
     *
     * @throws Exception
     */
    @XxlJob("PythonHandler")
    public void pythonJobHandler()throws Exception{
        log.debug("python 数据同步方法执行");
        String jobParam = XxlJobHelper.getJobParam();
        JSONObject jsonObject = JSONObject.parseObject(jobParam);
        Long dtId = jsonObject.getLong("dtId");
        if(ObjectUtil.isNotEmpty(dtId)){
            dataSetXxlBobService.processPythonData(dtId);
        }
    }
}
